#ifndef FGE_SPRITEBATCH_HPP
#define FGE_SPRITEBATCH_HPP

#include <string>

#include "Color.hpp"
#include "Math.hpp"

namespace fge
{

class Texture;
class Font;

enum BlendMode
{
	BM_None,
	BM_Alpha,
	BM_PremultipliedAlpha,
	BM_Additive
};

class SpriteBatch
{
public:
	SpriteBatch(int maxSpritesPerDraw = 1000);
	~SpriteBatch();

	void Begin(BlendMode blendMode = BM_Alpha, const fge::Matrix3 &batchTransform = fge::Matrix3::IDENTITY);
	void End();

	void Draw(Texture *texture,
		const Vector2 &position,
		Rect *sourceRectangle = NULL,
		const Vector2 &origin = Vector2(0, 0),
		const float rotation = 0,
		const Color &color = Color::White,
		const Vector2 &scale = Vector2::ONE,
		const Matrix3 &transformMatrix = Matrix3::IDENTITY);

	void DrawString(Font *font, 
		const std::string &s,
		const Vector2 &position,
		const Color &color,
		const float rotation = 0,
		const Vector2 &scale = Vector2::ONE,
		const Matrix3 &transformMatrix = Matrix3::IDENTITY);

private:
	void DrawBuffer();

	unsigned int vboId;
	unsigned int currentTextureId;
	BlendMode blendMode;

	Vertex *vertices;
	int maxVertices;
	int activeVertices;

	fge::Matrix3 batchTransform;
};

}

#endif//FGE_SPRITEBATCH_HPP
